package com.wu.cloud.userservice.controller;

import bean.PeskResponseEntity;
import bean.UserLoginEntity;
import bean.UserRegisterEntity;
import com.wu.cloud.userservice.service.UserAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;

;

/**
 * @author xwu36
 */

@RestController
@RequestMapping("/user")
public class AccountController {

    @Autowired
    @Qualifier("userAccountServiceImpl")
    UserAccountService userAccountService;

    @PostMapping("/info")
    public Principal user(Principal user){
        return user;
    }

    @PostMapping("/login")
    public PeskResponseEntity userLogin(@RequestBody UserLoginEntity userLoginEntity) {
        return userAccountService.login(userLoginEntity);
    }

    @PostMapping("/register")
    public PeskResponseEntity userRegister(@RequestBody UserRegisterEntity registerEntity) {
        return userAccountService.register(registerEntity);
    }

    @PutMapping("/forgot")
    public PeskResponseEntity userForgotPassword(@RequestParam String uid, @RequestParam String password) {
        return userAccountService.forget(uid, password);
    }

    @GetMapping("/old/password")
    public PeskResponseEntity queryOldPassword(@RequestParam String uid) {
        return userAccountService.queryOldPassword(uid);
    }
}
